package com.mes.web.controller.tdd;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.mes.entity.tdd.ProductRmoveDetail;
import com.mes.entity.tdd.tj.Tpage;
import com.mes.service.tdd.ProductRmoveService;
import com.mes.utils.DateJsonValueProcessor;
import com.mes.utils.ResponseUtil;

/**
 * 
 * @ClassName:ProductRmoveController
 * @Description:产品移库
 * @Author tdd
 * @Date 2018年3月22日上午11:22:24
 * @version 1.0
 */
@Controller
@RequestMapping("/productRmove")
public class ProductRmoveController {
	//引入产品移库service
	@Resource public ProductRmoveService productRmoveService;
	/**
	 * 产品移库详情分页列表查询
	 * @param request request对象
	 * @param pageBean 分页+条件
	 * @param limit 每页条数
	 * @param offset 条数
	 * @param response response对象
	 * @throws Exception 异常
	 */
	@RequestMapping("/list")
	public void materieDemandList(HttpServletRequest request,Tpage pageBean,@RequestParam(value="limit",required=false)String limit,@RequestParam(value="offset",required=false)String offset,HttpServletResponse response) throws Exception {
		
		//页数
		pageBean.setPage(Integer.parseInt(offset)/Integer.parseInt(limit));
		//每页条数
		pageBean.setPageSize(Integer.parseInt(limit));
		//分页列表查询
		List<ProductRmoveDetail> rmoveDetails=productRmoveService.list(pageBean);
		//总条数
		int total=productRmoveService.total(pageBean);
		//分页列表查询 和总条数传递到jsp
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
		JSONArray jsonArray = JSONArray.fromObject(rmoveDetails, jsonConfig);
		jsonObject.put("total", total);
		jsonObject.put("rows", jsonArray);
		ResponseUtil.write(response, jsonObject);
	}
	
}
